package com.pig4cloud.pig.demo.Controller;

import com.pig4cloud.pig.common.security.annotation.Inner;
import com.pig4cloud.pig.demo.Service.AdviseService;
import com.pig4cloud.pig.demo.feign.Entity.Announcement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("advise")
@Inner
@CrossOrigin
public class AdviseController {

    @Autowired
    private AdviseService adviseService;

    @GetMapping("/send/{input}/{title}")
    public void sendAdvise(@PathVariable String input,@PathVariable  String title) throws Exception {
        System.out.println("我是send");
        adviseService.sendToKafka(input,title);
    }

    @GetMapping("/findAnn/{id}")
    public List<Announcement> findA(@PathVariable(name="id") String id){
        System.out.println("执行了findAll");
        System.out.println(id);
        List<Announcement> annoucement = adviseService.findAnnoucement(id);
        return annoucement;
    }

    @GetMapping("/delAnn/{aid}/{uid}")
    public void delAnn(@PathVariable(name="aid") String aid,@PathVariable(name="uid") String uid){
        System.out.println("uid:"+uid+"   aid:"+aid);
        System.out.println("删除了");
        adviseService.delAnn(aid,uid);
    }

    @GetMapping("delAll/{uid}")
    public void delAll(@PathVariable(name="uid") String uid){
        System.out.println("删除了所有数据");
        adviseService.delAll(uid);
    }

}
